﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit;
using NUnit.Framework;
using XmlVisualizer;

namespace TestXmlVisualizer {
    [TestFixture]
    public class TestUtils {
        [Test]
        public void TestGetExtension() {
            String extension = XmlVisualizer.Utils.StringUtils.GetExtension("file.extension");
            Assert.AreEqual(".extension", extension);
        }

        [Test]
        public void TestGetExtensionEmpty() {
            String extension = XmlVisualizer.Utils.StringUtils.GetExtension("");
            Assert.AreEqual("", extension);
        }

        [Test]
        public void TestGetExtensionWithoutExtension() {
            String extension = XmlVisualizer.Utils.StringUtils.GetExtension("file");
            Assert.AreEqual("", extension);
        }

        [Test]
        public void TestRangeParsing() {
            IEnumerable<int> range = XmlVisualizer.Utils.StringUtils.RangeParsing("1-100,250-255");
            
            List<int> expected = new List<int>();
            for (int i = 1; i <= 100; ++i) {
                expected.Add(i);
            }
            for (int i = 250; i <= 255; ++i) {
                expected.Add(i);
            }
            CollectionAssert.AreEqual(expected, range);
        }

        [Test]
        public void TestRangeParsingOverlapping() {
            IEnumerable<int> actual = XmlVisualizer.Utils.StringUtils.RangeParsing("5-10,2-22");

            List<int> expected = new List<int>();
            for (int i = 2; i < 23; ++i) {
                expected.Add(i);
            }
            CollectionAssert.AreEqual(expected, actual);
        }

        [Test]
        public void TestBadRange() {
            IEnumerable<int> actual = XmlVisualizer.Utils.StringUtils.RangeParsing("-5-100,aa-bb");
            CollectionAssert.IsEmpty(actual);
        }
    }
}